package com.mdd.admin.controller.common;

import com.mdd.admin.service.index.IIndexVisitService;
import com.mdd.admin.service.order.IOrderRefundService;
import com.mdd.admin.service.order.IOrderService;
import com.mdd.admin.service.order.IRechargeOrderService;
import com.mdd.admin.service.user.IUserService;
import com.mdd.common.core.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("api/statistic")
public class StatisticController {

    @Resource
    private IOrderService orderService;

    @Resource
    private IOrderRefundService iOrderRefundService;

    @Resource
    private IUserService iUserService;

    @Resource
    private IRechargeOrderService iRechargeOrderService;

    @Resource
    private IIndexVisitService iIndexVisitService;

    /**
     * 财务概况
     *
     * @author panweiliang
     * @return AjaxResult
     */
    @GetMapping("/financialAffairs")
    public AjaxResult getFinancialAffairs() {
        Map<String, Object> statistic = this.orderService.getOrderStatistic();
        Map<String, Object> orderRefundStatistic = this.iOrderRefundService.getOrderStatistic();
        Map<String, Object> userStatisticData = this.iUserService.getStatisticData();
        statistic.putAll(orderRefundStatistic);
        statistic.putAll(userStatisticData);
        statistic.put("rechargeAmount", iRechargeOrderService.getRechargeAmount());
        statistic.put("rechargeOrderCount", iRechargeOrderService.getRechargeOrderCountByPayStatus(1));
        statistic.put("totalUserVisitCount", iIndexVisitService.getTotalVisitCount());
        return AjaxResult.success(statistic);
    }

}
